package com.zhang.apidriver.controller;

import com.zhang.apidriver.service.UserService;
import com.zhang.internalcommon.dto.*;
import com.zhang.internalcommon.utils.JwtUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import javax.servlet.http.HttpServletRequest;

/**
 * 类功能描述
 * 司机信息管理
 * @author Kye
 * @date 2025-04-12
 */
@RestController
public class UserController {
	@Autowired
	private UserService userService;

	@PutMapping("/user")
	public ResponseResult updateUser(@RequestBody DriverUser user) {
		ResponseResult responseResult = userService.updateUser(user);
		return responseResult;
	}

	@PostMapping("/driver-user-work-status")
	public ResponseResult changeWorkStatus(@RequestBody DriverUserWorkStatus driverUserWorkStatus){
		return userService.changeWorkStatus(driverUserWorkStatus);
	}

	@CrossOrigin
	@GetMapping("/driver-car-binding-relationship")
	public ResponseResult getDriverCarBindingRelationship(HttpServletRequest request){
		String authorization = request.getHeader("Authorization");
		TokenResult tokenResult = JwtUtils.checkToken(authorization);
		String phone = tokenResult.getPhone();
		ResponseResult<DriverCarBindingRelationship> driverCarBindingRelationship = userService.getDriverCarBindingRelationship(phone);
		return driverCarBindingRelationship;
	}
}
